﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GBT.ParamEntity;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using NLog;
using QueryDataLogic.Core;

namespace WebAPI_QiSiMealSystem.Controllers
{
    [Route("gbt/[controller]")]
    [ApiController]
    public class UserVerifyController : ControllerBase
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        UserVerify uv = new UserVerify();

        // GET: gbt/UserVerify
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: gbt/UserVerify/UserList/1/2
        [HttpGet("UserList/{CurrentPage}/{districtID}", Name = "UserList")]
        public async Task<IActionResult> GetUserList(int CurrentPage, int districtID)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.GetUserList(CurrentPage, districtID);
                }
                catch (Exception ex)
                {
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/UserListInfo
        [HttpPost("UserListInfo")]
        public async Task<IActionResult> GetUserInfo(System_MealUser mealUser)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                int totalNumber = 0;
                int totalPage = 0;
                string Error = "";
                object result = null;
                try
                {
                    result = uv.GetUserInfo(mealUser, ref totalNumber, ref totalPage);
                }
                catch (Exception ex)
                {
                    Error = ex.Message + Environment.NewLine + ex.StackTrace;
                    logger.Error(ex);
                }
                return Ok(new { data = result, totalNumber, totalPage });
            });
            return task;
        }

        // GET: gbt/UserVerify/UserInfo/5
        [HttpGet("UserInfo/{districtID}/{value}", Name = "UserInfo")]
        public async Task<IActionResult> Get(int districtID, string value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    //手机号码
                    //logger.Info(value);
                    joResult = uv.GetUserInfo(districtID, value);
                }
                catch (Exception ex)
                {
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // GET: gbt/UserVerify/SmsVerify/5
        [HttpGet("SmsVerify/{value}", Name = "SmsVerify")]
        public async Task<IActionResult> GetSmsVerify(string value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    //手机号码
                    //logger.Info(value);
                    joResult = uv.SmsVerify(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // GET: gbt/UserVerify/MobileVerify/5
        [HttpGet("MobileVerify/{districtID}/{value}", Name = "MobileVerify")]
        public async Task<IActionResult> GetMobileVerify(int districtID, string value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    //手机号码
                    //logger.Info(value);
                    joResult = uv.MobileVerify(districtID, value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // GET: gbt/UserVerify/UserNumberVerify/5
        [HttpGet("UserNumberVerify/{districtID}/{mobile}/{value}", Name = "UserNumberVerify")]
        public async Task<IActionResult> UserNumberVerify(int districtID, string mobile, string value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.UserNumberVerify(districtID, mobile, value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // GET: gbt/UserVerify/GetInvitationCode/1
        [HttpGet("GetInvitationCode/{districtID}", Name = "GetInvitationCode")]
        public async Task<IActionResult> GetInvitationCode(int districtID)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.GetInvitationCode(districtID);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/InvitationCodeVerify
        [HttpPost("InvitationCodeVerify")]
        public async Task<IActionResult> GetInvitationCodeVerify(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    //邀请码
                    //logger.Info(value);
                    joResult = uv.InvitationCodeVerify(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/SetUser
        [HttpPost("SetUser")]
        public async Task<IActionResult> Post([FromBody] JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    //JObject joParams = JObject.Parse(value);
                    joResult = uv.SetUserInfo(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/SetInvitationCode
        [HttpPost("SetInvitationCode")]
        public async Task<IActionResult> SetInvitationCode(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.SetInvitationCode(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/GetRegisterInfo
        [HttpPost("GetRegisterInfo")]
        public async Task<IActionResult> PostRegisterInfo(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.GetRegisterInfo(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/PasswordVerify
        [HttpPost("PasswordVerify")]
        public async Task<IActionResult> PostPasswordVerify(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.PasswordVerify(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/UserLoginVerify
        [HttpPost("UserLoginVerify")]
        public async Task<IActionResult> PostUserLoginVerify(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.UserLoginVerify(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/LoginVerify
        [HttpPost("LoginVerify")]
        public async Task<IActionResult> PostLoginVerify(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.LoginVerify(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/ModifyPassword
        [HttpPost("ModifyPassword")]
        public async Task<IActionResult> PostModifyPassword(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.ModifyPassword(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/UserVerify/ModifyUserPassword
        [HttpPost("ModifyUserPassword")]
        public async Task<IActionResult> PostModifyUserPassword(JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = uv.ModifyUserPassword(value);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // PUT: gbt/UserVerify/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE: gbt/ApiWithActions/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
